package com.yang.controller;

import com.yang.entity.NoteEmail;
import com.yang.service.NoteEmailService;
import com.yang.utils.PictureFactory;
import com.yang.entity.EmailSmsCountInfo;
import com.yang.utils.info.NoteResponseInfo;
import com.yang.entity.ProfileThings;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * 短信邮箱成功发送表(NoteEmail)表控制层
 *
 * @author yangdacheng
 * @since 2022-03-02 19:11:02
 */
@RestController
@RequestMapping("noteEmail")
@Slf4j
public class NoteEmailController{
    /**
     * 服务对象
     */
    @Resource
    private NoteEmailService noteEmailService;
    @Resource
    private PictureFactory pictureFactory;

    /**
     * 添加新的发送成功的邮件/短信
     * @param noteEmail
     * @return
     */
    @PostMapping("insertNoteEmail")
    public Boolean insertNoteEmail(NoteEmail noteEmail){
        return noteEmailService.insertNoteEmail(noteEmail);
    }

    /**
     * 获取成功发送的短信/邮件数量
     * @param noteEmail
     * @return
     */
    @PutMapping("queryAllNEByUID")
    public NoteResponseInfo queryAllNEByUID(NoteEmail noteEmail){
        log.info(noteEmail+"获取的数据");
        String profileTitle = "成功发送";
        String background = "#ffffff";
        switch (noteEmail.getNoteType()){
            case 0:
                profileTitle = "邮箱"+profileTitle;
                background = "#FCE4EC";
                break;
            case 1:
                profileTitle = "短信"+profileTitle;
                background = "#EDE7F6";
                break;
        }
        NoteResponseInfo noteResponseInfo = new NoteResponseInfo();
        //获取指定类型成功数量
        Integer getTypeResult = noteEmailService.queryEmailCount(
                noteEmail.getSendState(), noteEmail.getNoteType(), noteEmail.getUserid());
        ProfileThings profileThings = new ProfileThings(profileTitle,getTypeResult,background);
        noteResponseInfo.setNoteCode(200).setNoteMessage("请求成功").setNoteClass(profileThings);
        return noteResponseInfo;
    }

    /**
     * 获取图表1的数据
     * @param userID
     * @return
     */
    @GetMapping("getPicture/{userID}")
    public NoteResponseInfo getPictureData(@PathVariable("userID") String userID){
        NoteResponseInfo noteResponseInfo = new NoteResponseInfo();
        List<EmailSmsCountInfo> emailSmsCountInfos = pictureFactory.queryOneData(userID);
        return noteResponseInfo.setNoteCode(200).setNoteClass("获取成功").setNoteClass(emailSmsCountInfos);
    }
}